//
//  userNameField.m
//  GKBHouse
//
//  Created by XMYY-19 on 2017/8/31.
//
//

#import "userNameField.h"

@implementation userNameField
- (void)drawRect:(CGRect)rect
{
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    [[UIColor colorWithRGBColorByString:@"#6b79a0"] set];//设置下划线颜色 这里是红色 可以自定义
    
    CGFloat y = CGRectGetHeight(self.frame);
    
    CGContextMoveToPoint(context, 0, y);
    
    CGContextAddLineToPoint(context, CGRectGetWidth(self.frame), y);
    
    //设置线的宽度
    
    CGContextSetLineWidth(context, 2);
    
    //渲染 显示到self上
    
    CGContextStrokePath(context);
    
}
-(instancetype)initWithFrame:(CGRect)frame
{

    if (self = [super initWithFrame:frame]) {
        
        //UILabel *label = [[UILabel alloc] init];
        UIImageView *myImage = [[UIImageView alloc] init];
        
        self.leftView = myImage;
        
        self.leftViewMode = UITextFieldViewModeAlways;
        
        _leftImage = myImage;
        
    }
    
    return self;
    
 }

-(CGRect)leftViewRectForBounds:(CGRect)bounds
{
    [super leftViewRectForBounds:bounds];
    
    CGRect frame = bounds;
    
    //这里设置为leftView的宽是textField的0.3倍，
    
    frame.size.width = bounds.size.width * 0.3;
    
    return frame;

}

- (void)setPlaceholderColor:(UIColor *)placeholderColor

{
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    
    dict[NSForegroundColorAttributeName] = placeholderColor;
    
    NSAttributedString *attribute = [[NSAttributedString alloc] initWithString:self.placeholder attributes:dict];
    
    [self setAttributedPlaceholder:attribute];

}
- (void)setPlaceholderFont:(UIFont *)placeholderFont
{
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    
    dict[NSFontAttributeName] = placeholderFont;
    
    NSAttributedString *attribute = [[NSAttributedString alloc] initWithString:self.placeholder attributes:dict];
    
    [self setAttributedPlaceholder:attribute];
    
}

//- (void)setLeftTitleColor:(UIColor *)leftTitleColor
//
//{
//    
//    _leftTitleColor = leftTitleColor;
//    
//    [_leftLabel setTextColor:leftTitleColor];
//    
//}

-(void)setLeftImage:(UIImageView *)leftImage
{
    _leftImage  = leftImage;
    [_leftImage setImage:leftImage];
}

//- (void)setLeftTitle:(NSString *)leftTitle
//
//{
//    
//    _leftTitle = leftTitle;
//    
//    [_leftLabel setText:leftTitle];
//    
//}
@end
